package cn.zhangjie.tran;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

public class MyTranListener implements TransactionListener {
    //执行本地事务的方法   3步和第4步
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {

        try {
            System.out.println("执行了本地事务，并且成功了");
            //本地事务执行成功了。返回成功
            return LocalTransactionState.COMMIT_MESSAGE;
        } catch (Exception e) {
            e.printStackTrace();
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }
    }


    //回查方法5.6.7
    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        System.out.println("根据我们的订单编号，查询订单状态，决定返回成功还是失败");

        return LocalTransactionState.ROLLBACK_MESSAGE;

    }
}
